from django.db import models
from django.contrib.auth.models import User

class Node(models.Model):
    name=models.CharField(max_length=20)
    parent=models.ForeignKey('self',blank=True,null=True)
    founder=models.ForeignKey(User)
    manager=models.ManyToManyField(User,related_name='manage')
    def __unicode__(self):
        return self.name

class Post(models.Model):
    title=models.CharField(max_length=140)
    author=models.ForeignKey(User)
    node=models.ForeignKey(Node)
    post_time=models.DateTimeField(auto_now_add=True)
    replied_time=models.DateTimeField(auto_now_add=True)
    view_count=models.IntegerField(default=0)
    comment_count=models.IntegerField(default=0)
    content=models.TextField()
    def __unicode__(self):
        return self.title

class Comment(models.Model):
    author=models.ForeignKey(User)
    post=models.ForeignKey(Post)
    post_time=models.DateTimeField(auto_now_add=True)
    content=models.TextField()
    def __unicode__(self):
        return self.content[:100]